package cn.ibizlab.odoo.core.odoo_gamification.service.impl;

import java.io.Serializable;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.HashMap;
import java.math.BigInteger;
import java.util.Collection;

import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cglib.beans.BeanCopier;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import cn.ibizlab.odoo.core.client.model.Igamification_badge_user;
import cn.ibizlab.odoo.core.odoo_gamification.domain.Gamification_badge_user;
import cn.ibizlab.odoo.core.odoo_gamification.filter.Gamification_badge_userSearchContext;
import cn.ibizlab.odoo.core.odoo_gamification.service.IGamification_badge_userService;
import cn.ibizlab.odoo.util.SearchResult;
import cn.ibizlab.odoo.util.log.IBIZLog;

/**
 * 实体[游戏化用户徽章] 服务对象接口实现
 */
@Slf4j
@IBIZLog
@Service
public class Gamification_badge_userServiceImpl implements IGamification_badge_userService {

    @Autowired
    private cn.ibizlab.odoo.core.client.service.Igamification_badge_userClientService gamification_badge_userClientService;

    @Override
    public void removeBatch(Collection<? extends Serializable> idList, int batchSize) {

        //gamification_badge_userClientService.removeBatch(gamification_badge_users) ;

    }

    @Override
    public void updateBatch(List<Gamification_badge_user> gamification_badge_users, int batchSize) {

        //gamification_badge_userClientService.updateBatch(gamification_badge_users,batchSize) ;

    }

    @Override
    public void createBatch(List<Gamification_badge_user> gamification_badge_users, int batchSize) {

                        //gamification_badge_userClientService.createBatch(gamification_badge_users,batchSize) ;

    }

    @Override
    public Gamification_badge_user get(Integer id) {
        Igamification_badge_user clientModel = gamification_badge_userClientService.createModel();
        clientModel.setId(id);
        gamification_badge_userClientService.get(clientModel) ;
        return this.convert2Domain(clientModel,null);
    }

    @Override
    public Gamification_badge_user get(Gamification_badge_user gamification_badge_user) {
        Gamification_badge_user retgamification_badge_user = this.get(gamification_badge_user.getId()) ;
    	BeanCopier copier=BeanCopier.create(retgamification_badge_user.getClass(), gamification_badge_user.getClass(), false);
        copier.copy(retgamification_badge_user, gamification_badge_user, null);
        return gamification_badge_user ;
    }

    @Override
    public boolean update(Gamification_badge_user gamification_badge_user) {
        boolean bOk = false ;
        Igamification_badge_user clientModel = this.convert2Model(gamification_badge_user,null);
        gamification_badge_userClientService.update(clientModel) ;
        this.convert2Domain(clientModel,gamification_badge_user) ;
        bOk = true;
        return bOk ;
    }

    @Override
    public boolean remove(Integer id) {
        boolean bOk = false ;
        Igamification_badge_user clientModel = gamification_badge_userClientService.createModel();
        clientModel.setId(id);
        gamification_badge_userClientService.remove(clientModel) ;
        bOk = true ;
        return bOk ;
    }

    @Override
    public boolean create(Gamification_badge_user gamification_badge_user) {
        boolean bOk = false ;
        Igamification_badge_user clientModel = this.convert2Model(gamification_badge_user,null);
        gamification_badge_userClientService.create(clientModel) ;
        this.convert2Domain(clientModel,gamification_badge_user);
        bOk = true ;

        return bOk ;
    }

    /**
     * 查询集合 默认查询
     */
    @Override
    public Page<Gamification_badge_user> searchDefault(Gamification_badge_userSearchContext context) {
        List<Gamification_badge_user> list = new ArrayList<Gamification_badge_user>();
        Page<cn.ibizlab.odoo.core.client.model.Igamification_badge_user> clientModelList = gamification_badge_userClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Igamification_badge_user clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Gamification_badge_user>(list, context.getPageable(), clientModelList.getTotalElements());
    }


    /**
     * 根据游戏化徽章查询
     */
    @Override
    public Page<Gamification_badge_user> selectByOdoo_badge(Integer id){
        Gamification_badge_userSearchContext context = new Gamification_badge_userSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Gamification_badge_user> list = new ArrayList<Gamification_badge_user>();
        Page<cn.ibizlab.odoo.core.client.model.Igamification_badge_user> clientModelList = gamification_badge_userClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Igamification_badge_user clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Gamification_badge_user>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据游戏化挑战查询
     */
    @Override
    public Page<Gamification_badge_user> selectByOdoo_challenge(Integer id){
        Gamification_badge_userSearchContext context = new Gamification_badge_userSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Gamification_badge_user> list = new ArrayList<Gamification_badge_user>();
        Page<cn.ibizlab.odoo.core.client.model.Igamification_badge_user> clientModelList = gamification_badge_userClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Igamification_badge_user clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Gamification_badge_user>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据员工查询
     */
    @Override
    public Page<Gamification_badge_user> selectByOdoo_employee(Integer id){
        Gamification_badge_userSearchContext context = new Gamification_badge_userSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Gamification_badge_user> list = new ArrayList<Gamification_badge_user>();
        Page<cn.ibizlab.odoo.core.client.model.Igamification_badge_user> clientModelList = gamification_badge_userClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Igamification_badge_user clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Gamification_badge_user>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据用户查询
     */
    @Override
    public Page<Gamification_badge_user> selectByOdoo_create(Integer id){
        Gamification_badge_userSearchContext context = new Gamification_badge_userSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Gamification_badge_user> list = new ArrayList<Gamification_badge_user>();
        Page<cn.ibizlab.odoo.core.client.model.Igamification_badge_user> clientModelList = gamification_badge_userClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Igamification_badge_user clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Gamification_badge_user>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据用户查询
     */
    @Override
    public Page<Gamification_badge_user> selectByOdoo_sender(Integer id){
        Gamification_badge_userSearchContext context = new Gamification_badge_userSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Gamification_badge_user> list = new ArrayList<Gamification_badge_user>();
        Page<cn.ibizlab.odoo.core.client.model.Igamification_badge_user> clientModelList = gamification_badge_userClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Igamification_badge_user clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Gamification_badge_user>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据用户查询
     */
    @Override
    public Page<Gamification_badge_user> selectByOdoo_user(Integer id){
        Gamification_badge_userSearchContext context = new Gamification_badge_userSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Gamification_badge_user> list = new ArrayList<Gamification_badge_user>();
        Page<cn.ibizlab.odoo.core.client.model.Igamification_badge_user> clientModelList = gamification_badge_userClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Igamification_badge_user clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Gamification_badge_user>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据用户查询
     */
    @Override
    public Page<Gamification_badge_user> selectByOdoo_write(Integer id){
        Gamification_badge_userSearchContext context = new Gamification_badge_userSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Gamification_badge_user> list = new ArrayList<Gamification_badge_user>();
        Page<cn.ibizlab.odoo.core.client.model.Igamification_badge_user> clientModelList = gamification_badge_userClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Igamification_badge_user clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Gamification_badge_user>(list, context.getPageable(), clientModelList.getTotalElements());

    }



    public Igamification_badge_user convert2Model(Gamification_badge_user domain , Igamification_badge_user model) {
        if(domain == null)
            return model ;
        if(model==null){
            model = gamification_badge_userClientService.createModel() ;
        }

         if(domain.getCreate_dateDirtyFlag())
            model.setCreate_date(domain.getCreate_date());
         if(domain.getDisplay_nameDirtyFlag())
            model.setDisplay_name(domain.getDisplay_name());
         if(domain.getIdDirtyFlag())
            model.setId(domain.getId());
         if(domain.getWrite_dateDirtyFlag())
            model.setWrite_date(domain.getWrite_date());
         if(domain.getCommentDirtyFlag())
            model.setComment(domain.getComment());
         if(domain.get__last_updateDirtyFlag())
            model.set__last_update(domain.get__last_update());
         if(domain.getUser_id_textDirtyFlag())
            model.setUser_id_text(domain.getUser_id_text());
         if(domain.getSender_id_textDirtyFlag())
            model.setSender_id_text(domain.getSender_id_text());
         if(domain.getLevelDirtyFlag())
            model.setLevel(domain.getLevel());
         if(domain.getWrite_uid_textDirtyFlag())
            model.setWrite_uid_text(domain.getWrite_uid_text());
         if(domain.getCreate_uid_textDirtyFlag())
            model.setCreate_uid_text(domain.getCreate_uid_text());
         if(domain.getBadge_nameDirtyFlag())
            model.setBadge_name(domain.getBadge_name());
         if(domain.getChallenge_id_textDirtyFlag())
            model.setChallenge_id_text(domain.getChallenge_id_text());
         if(domain.getEmployee_id_textDirtyFlag())
            model.setEmployee_id_text(domain.getEmployee_id_text());
         if(domain.getSender_idDirtyFlag())
            model.setSender_id(domain.getSender_id());
         if(domain.getBadge_idDirtyFlag())
            model.setBadge_id(domain.getBadge_id());
         if(domain.getChallenge_idDirtyFlag())
            model.setChallenge_id(domain.getChallenge_id());
         if(domain.getEmployee_idDirtyFlag())
            model.setEmployee_id(domain.getEmployee_id());
         if(domain.getCreate_uidDirtyFlag())
            model.setCreate_uid(domain.getCreate_uid());
         if(domain.getWrite_uidDirtyFlag())
            model.setWrite_uid(domain.getWrite_uid());
         if(domain.getUser_idDirtyFlag())
            model.setUser_id(domain.getUser_id());
        return model ;
    }

    public Gamification_badge_user convert2Domain( Igamification_badge_user model ,Gamification_badge_user domain) {
        if(model == null)
            return domain ;
        if(domain == null){
            domain = new Gamification_badge_user();
        }

        if(model.getCreate_dateDirtyFlag())
            domain.setCreate_date(model.getCreate_date());
        if(model.getDisplay_nameDirtyFlag())
            domain.setDisplay_name(model.getDisplay_name());
        if(model.getIdDirtyFlag())
            domain.setId(model.getId());
        if(model.getWrite_dateDirtyFlag())
            domain.setWrite_date(model.getWrite_date());
        if(model.getCommentDirtyFlag())
            domain.setComment(model.getComment());
        if(model.get__last_updateDirtyFlag())
            domain.set__last_update(model.get__last_update());
        if(model.getUser_id_textDirtyFlag())
            domain.setUser_id_text(model.getUser_id_text());
        if(model.getSender_id_textDirtyFlag())
            domain.setSender_id_text(model.getSender_id_text());
        if(model.getLevelDirtyFlag())
            domain.setLevel(model.getLevel());
        if(model.getWrite_uid_textDirtyFlag())
            domain.setWrite_uid_text(model.getWrite_uid_text());
        if(model.getCreate_uid_textDirtyFlag())
            domain.setCreate_uid_text(model.getCreate_uid_text());
        if(model.getBadge_nameDirtyFlag())
            domain.setBadge_name(model.getBadge_name());
        if(model.getChallenge_id_textDirtyFlag())
            domain.setChallenge_id_text(model.getChallenge_id_text());
        if(model.getEmployee_id_textDirtyFlag())
            domain.setEmployee_id_text(model.getEmployee_id_text());
        if(model.getSender_idDirtyFlag())
            domain.setSender_id(model.getSender_id());
        if(model.getBadge_idDirtyFlag())
            domain.setBadge_id(model.getBadge_id());
        if(model.getChallenge_idDirtyFlag())
            domain.setChallenge_id(model.getChallenge_id());
        if(model.getEmployee_idDirtyFlag())
            domain.setEmployee_id(model.getEmployee_id());
        if(model.getCreate_uidDirtyFlag())
            domain.setCreate_uid(model.getCreate_uid());
        if(model.getWrite_uidDirtyFlag())
            domain.setWrite_uid(model.getWrite_uid());
        if(model.getUser_idDirtyFlag())
            domain.setUser_id(model.getUser_id());
        return domain ;
    }


}
